//
//  TCMyMessageCell.m
//  陶瓷
//
//  Created by 王戈 on 15/8/3.
//  Copyright (c) 2015年 王戈. All rights reserved.
//

#import "TCMyMessageCell.h"

@interface TCMyMessageCell ()

@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UIView *grayLine;

@end

@implementation TCMyMessageCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *ID = @"TCMyMessageCell";
    TCMyMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[TCMyMessageCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];

        [self.contentView addSubview:self.typeLabel];
        [self.contentView addSubview:self.grayLine];
    }
    return self;
}

- (void)setMessage:(MessageModel *)message {
    _message = message;
    
    self.textLabel.text = message.Title;
    self.detailTextLabel.text = message.StateStr;
    switch (message.Type) {
        case kTCMessageTypeRent:
            self.typeLabel.text = @"商铺信息";
            self.type = kTCMessageTypeRent;
            self.imageView.image = [UIImage imageNamed:@"deepblue_line"];
            break;
        case kTCMessageTypeRecruitment:
            self.typeLabel.text = @"招聘信息";
            self.type = kTCMessageTypeRecruitment;
            self.imageView.image = [UIImage imageNamed:@"blue_line"];
            break;
        case kTCMessageTypeTailGoods:
            self.typeLabel.text = @"尾货信息";
            self.type = kTCMessageTypeTailGoods;
            self.imageView.image = [UIImage imageNamed:@"purple_line"];
            break;
        default:
            break;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    

    
    self.imageView.frame = CGRectMake(0, 0, 6, self.height);
    
    [_typeLabel sizeToFit];
    _typeLabel.centerY = self.contentView.centerY;
    _typeLabel.x = self.contentView.width - 30 - _typeLabel.width;
    
    _grayLine.frame = CGRectMake(0, self.height - 0.5, self.width, 0.5);
    CGRect frame = self.textLabel.frame;
    frame.size.width = kDefaultWindowWidth/2;
    self.textLabel.frame = frame;
}

- (UILabel *)typeLabel {
    if (_typeLabel == nil) {
        _typeLabel = [[UILabel alloc] init];
    }
    return _typeLabel;
}

- (UIView *)grayLine {
    if (_grayLine == nil) {
        _grayLine = [[UIView alloc] init];
        _grayLine.backgroundColor = [UIColor lightGrayColor];
    }
    return _grayLine;
}
@end
